using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using DALTMClient.WSDL;

namespace DALTMClient
{
    public partial class frmCreateAccount : Form
    {
        AluMessenger chat = new AluMessenger();

        public frmCreateAccount()
        {
            InitializeComponent();
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            lblMess.ForeColor = Color.Red;
            if (txtUserName.Text != null)
            {
                if (!txtUserName.Text.Equals("") && !txtPass.Text.Equals("") && txtRePass.Text.Equals(txtPass.Text) && !txtAnswer.Text.Equals(""))
                {
                    string gender = "Male";
                    if (rdbFemale.Checked) gender = "Female";
                    if (!chat.IsExistsUserName(txtUserName.Text))
                    {
                        string pass = MD5Hash.Encoded(txtPass.Text);
                        bool ok = chat.CreateNewAccount(txtUserName.Text, pass, txtFullName.Text, gender, dtpBirthday.Value.ToString(), txtCountry.Text, txtCity.Text, txtTelephone.Text, txtEmail.Text, cboQuery.Text, txtAnswer.Text);
                        if (ok)
                        {
                            pnlType.Visible = false;
                            lblMess.ForeColor = Color.Blue;
                            lblMess.Text = "Created new account successful!";
                            btnNext.Visible = false;
                            btnCancel.Visible = false;
                            btnFinish.Visible = true;

                        }
                        else
                            lblMess.Text = "Created new not successful! Please check and try again !";
                    }
                    else
                        MessageBox.Show("Please enter an account different ! Because this account already !","Alu! Messenger");
                }
                else
                    lblMess.Text = "Created new not successful! Please check and try again !";
            }
            else
            {
                lblMess.Text = "Please enter your username !";
            }
        }

        private void btnFinish_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmCreateAccount_Load(object sender, EventArgs e)
        {

        }
    }
}